<template>
  <el-menu
      :default-openeds="['2', '3','4']"
      style="min-height: 100%; overflow-x: hidden"
      background-color="rgb(39 122 207 / 100%)"
      text-color="#fff"
      active-text-color="#ffd04b"
      :collapse-transition="false"
      :collapse="isCollapse"
      router=""
  >
    <div style="height: 60px; line-height: 60px; text-align: center">
      <img
          src="../../public/school.png"
          alt=""
          style="width: 25px; position: relative; top: 5px; right: 5px"
      />
      <b style="color: white" v-show="logoTextShow">高校资产管理系统</b>
    </div>
    <el-menu-item index="/">
      <template slot="title">
        <i class="el-icon-house"></i>
        <span slot="title">首页</span>
      </template>
    </el-menu-item>
    <el-submenu index="3">
      <template slot="title">
        <i class="el-icon-share"></i>
        <span slot="title">资产管理</span>
      </template>
      <el-menu-item-group>
        <el-menu-item index="/submitAppliance" v-show="check('submitAppliance')">
          {{ getName('submitAppliance') }}
        </el-menu-item>
        <el-menu-item index="/check" v-show="check('check')">{{ getName('check') }}</el-menu-item>
        <el-menu-item index="/asset" v-show="check('asset')">{{ getName('asset') }}</el-menu-item>
        <el-menu-item index="/lendin" v-show="check('lendin')">{{ getName('lendin') }}</el-menu-item>
        <el-menu-item index="/lendaduit" v-show="check('lendaduit')">{{ getName('lendaduit') }}</el-menu-item>
        <el-menu-item index="/lendout" v-show="check('lendout')">{{ getName('lendout') }}</el-menu-item>
      </el-menu-item-group>
    </el-submenu>
    <el-submenu index="4">
      <template slot="title">
        <i class="el-icon-setting"></i>
        <span slot="title">资产维修</span>
      </template>
      <el-menu-item-group>
        <el-menu-item index="/maintainsubmit" v-show="check('maintainsubmit')">
          {{ getName('maintainsubmit') }}
        </el-menu-item>
        <el-menu-item index="/maintain" v-show="check('maintain')">{{ getName('maintain') }}</el-menu-item>
      </el-menu-item-group>
    </el-submenu>
    <el-menu-item index="/user" v-show="check('user')">
      <template slot="title">
        <i class="el-icon-s-custom"></i>
        <span slot="title">{{ getName('user') }}</span>
      </template>

    </el-menu-item>
  </el-menu>
</template>

<script>
import {getUser} from "@/utils/tools";
import router from "@/router";

export default {
  name: "Aside",
  props: {
    isCollapse: Boolean,
    logoTextShow: Boolean,
  },
  data() {
    return {
      user: getUser(),
      listQuanXian: [],
      arrQx: [],
    };
  },
  computed: {},
  mounted() {
    this.load();
  },
  methods: {
    load() {
      if (this.user && this.user.userId) {
        this.request.post("/sysuser/listUserRole", {id: this.user.userId}).then((res) => {
          if (res.success) {
            this.listQuanXian = res.data;
            if (this.listQuanXian.length > 0) {
              this.arrQx = this.listQuanXian.map(map => map.menuKey)
            }
          } else {
            this.$message.error("获取数据失败");
          }
        });
      }
    },
    check(key) {
      return this.arrQx.indexOf(key) > -1;
    },
    getName(key) {
      let name = '';
      let ro = router['_path'];
      for (let o in ro) {
        if (ro[o].path == key) {
          name = ro[o].name;
          break;
        }
      }
      return name;
    }
  }
}
</script>